const express = require('express')
const multer = require('multer')
const app = express()
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, './uploads')
  },
  filename: function (req, file, cb) {
    const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
    cb(null, file.fieldname + '-' + uniqueSuffix)
  }
})

const upload = multer({ storage: storage })
// app.use(express.json())
// app.use(express.urlencoded({extended: true}))
// app.use(upload.arra())
// app.post('/login', (req, res, next) => {
//   console.log(req.body)
//   res.end('login server')
// })
app.post('/upload', upload.array('avatar'), (req, res, next) => {
  console.log(req.files)
  res.end('文件上传成功')
})
app.listen(6902, () => {
  console.log('form-data中间件的解析')
})